import UtilsDate from './index';
import type { IUtilsDate } from "./date";

describe('UtilsDate', () => {
    let utilsDate: IUtilsDate;

    beforeEach(() => {
        utilsDate = UtilsDate;
    });

    test('format() should format date correctly', () => {
        const date = '2023-09-15';
        const params = {format: 'yyyy-MM-dd'};
        const result = utilsDate.format(date, params);
        expect(result).toEqual('2023-09-15');
    });

    test('formatUTC() should format date in UTC correctly', () => {
        const date = '2023-09-15';
        const params = {format: 'yyyy-MM-dd'};
        const result = utilsDate.formatUTC(date, params);
        // 验证结果是否符合预期
        expect(result).toEqual('2023-09-15');
    });

    test('formatToUTC() should format date to UTC correctly', () => {
        const date = '2023-09-15';
        const params = {format: 'yyyy-MM-dd'};
        const result = utilsDate.formatToUTC(date, params);
        // 验证结果是否符合预期
        expect(result).toEqual('2023-09-14');
    });

    test('formatToJson() should format date to JSON correctly', () => {
        const date = '2023-09-15';
        const params = {};
        const result = utilsDate.formatToJson(date, params);
        // 验证结果中的各个字段是否正确
        expect(result.yyyy).toEqual("2023");
    });

    test('countDown() should start countdown and call callbacks', () => {
        const endDate = new Date().getTime() + 10000;
        const params = {
            format: 'dd hh:mm:ss',
            startCallback: jest.fn(),
            callback: jest.fn(),
            endCallback: jest.fn(),
        };
        utilsDate.countDown(endDate, params);
        // 模拟时间流逝，验证回调函数是否被正确调用
    });
});
